#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/7/17  14:28
# @Author: 余浪人
# @email: yulangren520@gmail.com

from apps.models import db, BaseModel,datetime


class TL_System_Model(BaseModel):
    web_name = db.Column(db.String(255), default='', comment='网站名称')
    web_subtitle = db.Column(db.String(255), default='', comment='网站副标题')
    web_key = db.Column(db.String(255), default='', comment='关键词')
    web_description = db.Column(db.Text, default='', comment='网站描述')
    web_domain = db.Column(db.String(100),  comment='网站域名')
    web_logo = db.Column(db.String(255), default='', comment='网站logo')
    web_ico = db.Column(db.String(255), default='', comment='浏览器图标')
    web_stat = db.Column(db.Text, default='', comment='统计代码')
    web_close_tips = db.Column(db.Text, default='', comment='站点关闭提示')
    web_company = db.Column(db.String(255), default='', comment='公司/单位/团体名称')
    web_authorization_code = db.Column(db.String(255), default='', comment='授权码')
    web_contact_adders = db.Column(db.String(255), default='', comment='联系地址')
    web_contact_tel = db.Column(db.String(11), default='', comment='联系电话')
    web_info_copyright = db.Column(db.String(255), default='', comment='版权信息')
    web_record = db.Column(db.String(100), default='蜀ICP备10000号', comment='备案号')
    web_gongan = db.Column(db.String(100), default='', comment='公安备案号')
    web_contact_qq = db.Column(db.String(255), default='1368419640', comment='联系QQ')
    web_contact_email = db.Column(db.String(255), default='1368419640@qq.com', comment='联系邮箱')
    web_content_on_off = db.Column(db.Integer, default=1, comment='系统评论| 0:停用  1:启用')
    web_on_off = db.Column(db.Integer, default=1, comment='站点开关| 0:停用  1:启用')
    web_type = db.Column(db.Integer, default=1, comment='站点类型| 1:动态  2:静态')

    def __repr__(self):
        return f'站点名称: {self.web_name}'

    def keys(self):
        return 'web_name', 'web_subtitle', 'web_key', 'web_description', 'web_domain', 'web_logo', 'web_ico', 'web_stat', 'web_close_tips', 'web_company', 'web_contact_adders', 'web_contact_tel', 'web_info_copyright', 'web_record', 'web_contact_qq', 'web_contact_email', 'web_content_on_off', 'web_on_off', 'id','web_gongan','web_type'


class TL_Notice_Model(BaseModel):
    notice_title = db.Column(db.String(128), comment='公告标题')
    notice_promulgator = db.Column(db.String(10), comment='公告发布者')
    notice_content = db.Column(db.Text, comment='公告内容')

    def __repr__(self):
        return f'当前公告:<{self.notice_title}>'

    def keys(self):
        return 'notice_title', 'notice_promulgator', 'notice_content'


class TL_Ad_Model(BaseModel):
    ad_name = db.Column(db.String(128), comment='广告名称')
    ad_code = db.Column(db.Text, default='', comment='广告代码')
    ad_end_date = db.Column(db.DateTime, default=datetime.now(), comment='到期时间')
    ad_remark = db.Column(db.String(255), default='', comment='广告备注')

    def __repr__(self):
        return f'广告名称:{self.ad_name}'

    def keys(self):
        return 'ad_name', 'ad_code', 'ad_end_date', 'ad_remark', 'status',


class TL_Blogroll_Model(BaseModel):
    link_name = db.Column(db.String(255), comment='链接名称')
    link_url = db.Column(db.String(255), comment='链接地址')
    link_end_date = db.Column(db.DateTime, default=datetime.now(), comment='到期时间')
    link_color = db.Column(db.String(10), comment='链接颜色')
    link_sort = db.Column(db.Integer, default=0, comment='链接排序')
    link_remark = db.Column(db.String(255), comment='备注说明')

    def __repr__(self):
        return f'链接名称: {self.link_name}'

    def keys(self):
        return 'link_name', 'link_url', 'link_end_date', 'link_color', 'link_sort', 'status', 'link_remark'


class TL_PayConf_Model(BaseModel):
    app_id = db.Column(db.String(32), comment='app_id')
    public_key = db.Column(db.Text, comment='公钥')
    private_key = db.Column(db.Text, comment='私钥')

    def keys(self):
        return 'app_id', 'public_key', 'private_key'


class TL_Redis_Model(BaseModel):
    redis_host = db.Column(db.String(32), default='localhost', comment='redis_host')
    redis_port = db.Column(db.Integer, default=6379, comment='redis_port')
    redis_password = db.Column(db.String(255), default='', comment='redis_password')

    def __repr__(self):
        return f'Redis:{self.redis_host}'

    def keys(self):
        return 'redis_host', 'redis_port', 'redis_password'

class TL_MySql_Model(BaseModel):
    mysql_host = db.Column(db.String(32), default='127.0.0.1')
    mysql_dbName = db.Column(db.String(128))
    mysql_user = db.Column(db.String(128))
    mysql_password= db.Column(db.String(128))
    mysql_port= db.Column(db.Integer, default=3306, comment='redis_host')


class TL_Email_Model(BaseModel):
    MAIL_PROT = db.Column(db.Integer, default=25, comment='端口')
    MAIL_SERVER = db.Column(db.String(32), default='smtp.qq.com', comment='邮件服务器')
    MAIL_USERNAME = db.Column(db.String(64), comment='发送邮箱号')
    MAIL_PASSWORD = db.Column(db.String(256), comment='邮箱授权码')
    MAIL_USE_SSL = db.Column(db.Integer, default=0, comment='开启SSL| 0:停用  1:启用')

    def __repr__(self):
        return f'邮件账户为: {self.MAIL_USERNAME}'

    def keys(self):
        return 'MAIL_PROT', 'MAIL_SERVER', 'MAIL_USERNAME', 'MAIL_PASSWORD', 'MAIL_USE_SSL'


class TL_Save_Model(BaseModel):
    save_classification = db.Column(db.Integer,default=1,comment='存储方式')
    save_path = db.Column(db.String(32), default='/uploads', comment='存储目录')
    bucket_name = db.Column(db.String(64), comment='空间名称')
    bucket_domain = db.Column(db.String(64), default='http://', comment='空间域名')
    access_key = db.Column(db.String(64), comment='ACCESS_KEY')
    secret_key = db.Column(db.String(64), comment='SECRET_KEY')

    def __repr__(self):
        return f'七牛云空间: {self.bucket_name}'

    def keys(self):
        return 'save_classification', 'save_path', 'bucket_name', 'access_key', 'secret_key', 'bucket_domain'


class TL_Validation_Model(BaseModel):
    v_code = db.Column(db.String(512), index=True)
